package com.zbkj.crmeb.chant.controller;


import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.chant.model.MerchantAddress;
import com.zbkj.crmeb.chant.request.EnableTakeAddressRequest;
import com.zbkj.crmeb.chant.request.SaveTakeAddressRequest;
import com.zbkj.crmeb.chant.service.MerchantAddressService;
import com.zbkj.crmeb.merchant.admin.controller.AdminBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2021-10-27
 */
@RestController
@RequestMapping("api/admin/chant/merchant-address")
@Api(tags = "平台售后地址")
public class ChantAddressController extends AdminBaseController {

    @Autowired
    private MerchantAddressService merchantAddressService;

    @ApiOperation(value = "售后地址列表")
    @GetMapping(value = "/afterSale/list")
    public CommonResult<CommonPage<MerchantAddress>> getAfterSaleAddressList(PageParamRequest request){
        return CommonResult.success(CommonPage.restPage(merchantAddressService.getTakeAddressList(request,0,2)));
    }

    @ApiOperation(value = "新增/编辑售后地址")
    @PostMapping(value = "/afterSale/save")
    public CommonResult<String> saveAfterSaleAddress(@RequestBody @Validated SaveTakeAddressRequest request){
        return merchantAddressService.saveTakeAddress(request,0,2);
    }

    @ApiOperation(value = "删除售后地址")
    @DeleteMapping(value = "/afterSale/delete/{id}")
    public CommonResult<String> deleteAfterSaleAddress(@ApiParam(value = "地址id", required = true) @PathVariable("id") Integer id){
        return merchantAddressService.deleteTakeAddress(id,0,2);
    }

}

